package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:tanxin Desc: 查询所有商品种类
 * @date:2020/7/11 8:30
 */
@Slf4j
@RestController
@RequestMapping("/shopping")
@Anoymous
public class ProductCategoryController {

    @Reference(timeout = 3000,check = false)
    IProductCateService productCateService;

    @GetMapping("/categories")
    public ResponseData queryProductCategories(@RequestParam(value = "sort", required = false, defaultValue = "1") String sort){
        AllProductCateRequest cateRequest = new AllProductCateRequest();
        cateRequest.setSort(sort);
        AllProductCateResponse cateResponse = productCateService.getAllProductCate(cateRequest);
        if (ShoppingRetCode.SUCCESS.getCode().equals(cateResponse.getCode())){
            return new ResponseUtil<>().setData(cateResponse.getProductCateDtoList());
        }
        return new ResponseUtil<>().setErrorMsg(SysRetCodeConstants.DB_EXCEPTION.getMessage());
    }
}
